/*
 * Created on May 12, 2005
 *
 */
package org.mushroomdb.query.impl.condition;

import org.mushroomdb.catalog.Column;
import org.mushroomdb.catalog.Register;

/**
 * @author Matias
 *
 */
public class EqualsToCondition extends EvaluationCondition {
	private boolean sign;

	/**
	 * 
	 */
	public EqualsToCondition(Column column, Object value, boolean sign) {
		super(column,value);
		this.sign = sign;
	}

	/**
	 * 
	 * @return
	 */
	public boolean isSign() {
		return this.sign;
	}

	/**
	 * @see org.mushroomdb.query.impl.condition.EvaluationCondition#evaluate(com.mdlm.rdbms.catalog.Register)
	 */
	public boolean evaluate(Register register) {
		Column column = this.getColumn();
		Object value = this.getValue();
		
		Object left = register.getValue(register.getColumnIndex(column));
		Object right = null;
		if (value instanceof Column) {
			right = register.getValue(register.getColumnIndex((Column) value));
		} else {
			right = value;
		}
		
		if (sign) {
			return left.equals(right);
		} else {
			return !left.equals(right);
		}
	}

	/**
	 * toString
	 */
	public String toString() {
		return this.getColumn().toString() +
			(this.sign ? "=" : "<>") + //$NON-NLS-1$ //$NON-NLS-2$
			this.getValue().toString(); //$NON-NLS-1$
	}
}
